<template>
    <div class="orderlist-container">
        <i-tabs :current="current" @change='handleChange'>
            <i-tab key="all" title="全部"  ></i-tab>
            <i-tab key="init" title="待付款"  ></i-tab>
            <i-tab key="success" title="待发货" ></i-tab>
            <i-tab key="delivery" title="已发货" ></i-tab>
            <i-tab key="evaluation" title="待评价" ></i-tab>
        </i-tabs>

        <div class="orders">
            <div class="order-item" v-for="(order,oindex) in currentList" :key="order.id">
                <i-card class="icard" full> 
                    
                    <div slot="content" class="content-item">
                       <div class="header" slot="title">
                            <img src="../../../static/images/logo1.png" alt="">
                            <div class="title">四川纤纸洁纸业</div>
                            <div class="status">{{ ORDERSTATUS[order.orderStatus] }}</div>
                        </div>

                        <div v-for="good in order.Goods" :key="good.id" class="detail-content">
                            <img :src="good.goods_id.imageList[0].url" alt="">
                            <div style="display:inline-block;text-indent:0.5em;">{{good.goods_id.name}} x {{good.amount}}</div>
                        </div>
                       
                        <div class="compute-content">
                            合计：共{{ order.allAmount }}件商品，实付 <div class="price">￥{{ order.allprice}}</div> 
                        </div>
                    </div>                    
                    <!-- <div slot="footer" class="footer-content" @click="toDetail(order.objectId,oindex)">查看详情</div> -->
                </i-card>
            </div>
        </div>
    </div>
</template>
<script>
 import {
    get,
    post,
    login,
    getStorageOpenid
  } from "../../utils";
export default {
    data(){
        return {
            current: 'all',
            user:'',
            ORDERSTATUS:['待付款','待发货','已发货','待评价'],
            orderList:[
            ],
            currentList:[],
            shopId:'',
            currentType:''
        }
    },
     watch:{
         orderList(){
             this.updateList()
         }
     },
    onLoad(query){
        // console.log(query.id)
        console.log(query)

        if(query.type)
            this.current = query.type;
    },    
    mounted(){
        // debugger
        this.user = getStorageOpenid()

        this.getAllRecords()
        console.log(this.currentType)
        if(this.currentType){
            this.current = this.currentType
            this.updateList();
        }
    },
    methods:{
         handleChange({target}){
            console.log('test')
             
            this.current = target.key
            this.updateList();
        },
        updateList(){
            let status = this.current.toUpperCase()
            console.log(status)
            switch(status){
                case 'INIT':
                    this.currentList = this.orderList.filter(item=>{
                        return item.orderStatus == 0
                    })
                    break;
                case 'SUCCESS':
                    
                    this.currentList = this.orderList.filter(item=>{
                        return item.orderStatus == 1
                    })
                    break;
                case 'DELIVERY':
                     this.currentList = this.orderList.filter(item=>{
                        return item.orderStatus == 2
                    })
                    break;
                case 'EVALUATION':
                     this.currentList = this.orderList.filter(item=>{
                        return item.orderStatus == 3
                    })
                    break;
                case 'FINISH':code = 4;
                    this.currentList = this.orderList.filter(item=>{
                            return item.orderStatus == 4
                })
                    break;
                default :
                    this.currentList = this.orderList;
                    break;
            }
        },
        async getAllRecords(){
            console.log(this.user)

            const data = await get("/order/list", {
                    id: this.user
                });            
            if(data&&data.length>0){        
                this.orderList = data;
                // this.currentList = data;
            }
        },
        toDetail(id,index){
            console.log(id)
        }
    }
}
</script>

<style lang="scss" scoped>
@import "./style";
</style>

